package com.hanamaki.jdbc.until;

import java.sql.*;

/**
 * @author hanamaki
 * @version 1.0
 * @date 2021/7/1 13:49
 */
public class JDBC_C3P0_Util_Test {

    public static void main(String[] args) throws Exception {

        testJdbc("scores");

    }

    // 测试 JDBC 简单的工具类的使用
    /**
     *
     * @param tableName  想要查询的表的名称
     */
    public static void testJdbc(String tableName) throws Exception{
        Connection con = JDBC_C3P0_Util.getCon();
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            statement = con.createStatement();
            String sql = "select * from " + tableName;
            resultSet = statement.executeQuery(sql);
            while (resultSet.next()) {
                System.out.println(resultSet.getObject(1));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            JDBC_C3P0_Util.refresh(con, statement, resultSet, null);
        }
    }
}
